import pandas as pd


def merge_results(full_df, text_results, symbol_results):
    """合并文本和符号校对结果"""
    # 合并所有结果
    all_results = pd.concat([text_results, symbol_results])

    # 按全局行号排序
    all_results.sort_values(by="全局行号", inplace=True)

    # 合并到完整数据
    merged_df = full_df.merge(
        all_results[["全局行号", "校对结果"]],
        on="全局行号",
        how="left"
    )

    # 填充缺失值
    merged_df["校对结果"] = merged_df["校对结果"].fillna("未校对")

    # 添加校对状态列
    merged_df["校对状态"] = merged_df["校对结果"].apply(
        lambda x: "通过" if "通过" in x else "未通过" if x != "未校对" else "未校对"
    )

    return merged_df